#define _CRT_SECURE_NO_WARNINGS 1

#include <vector>
using namespace std;

class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
        int n = timeSeries.size();
        int ret = 0;
        for (int i = 0; i < n - 1; ++i)
        {
            int gap = timeSeries[i + 1] - timeSeries[i];
            if (gap < duration) ret += gap;
            else ret += duration;
        }
        ret += duration;
        return ret;
    }
};